//指定中文输出编码
phantom.outputEncoding="GBK";
var fs = require('fs');
var casper = require('casper').create();

//写文件
casper.start('https://www.baidu.com/',function(){
	if(fs){
		var title = this.getTitle();
		this.echo("获取的title" + title);
		fs.write("test.txt","www.baidu.com " + title + "\n",'a');

	}
});

//读取文件
casper.then(function(){
	var data = fs.read('test.txt');
	this.echo(data);
});

//删除文件
/*casper.then(function(){
	fs.remove('test.txt');
});*/

casper.run();